# -*- coding:utf-8 -*-
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    # 返回从尾部到头部的列表值序列，例如[1,2,3]
    def printListFromTailToHead(self, listNode):
        # write code here
        res = None
        while listNode:
            var = listNode.next
            listNode.next = res
            res = listNode
            listNode = var
        array_list = []
        while res:
            array_list.append(res.val)
            res = res.next
        return array_list



# -*- coding:utf-8 -*-# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = Noneclass Solution:
#  返回从尾部到头部的列表值序列，例如[1,2,3]
def printListFromTailToHead(self, listNode):
#  write code here
    if listNode is None:
        return []
    return self.printListFromTailToHead(listNode.next) + [listNode.val]